﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WareHouse.App
{
    using WareHouse.Contract.Services;
    using WareHouse.Service.Services;

    public partial class FrmReport : Form
    {
        private IWareHouseService wareHouseService;
        public FrmReport()
        {
            wareHouseService=new WareHouseService();
            InitializeComponent();
        }

        private void FrmReport_Load(object sender, EventArgs e)
        {
            dtpDateCreate.EditValue = DateTime.Now;
            LoadWareHouse();
           
        }
        private void LoadWareHouse()
        {
            ddlWareHouseSale.DataSource = wareHouseService.ListWareHouse();
            ddlWareHouseSale.DisplayMember = "WareHouseName";
            ddlWareHouseSale.ValueMember = "WareHouseId";
        }
        private void ReCanculateSTT()
        {
            for (int i = 0; i < gridView2.RowCount; i++)
            {
                gridView2.SetRowCellValue(i, "Stt", i + 1);
            }

            for (int i = 0; i < gridView1.RowCount; i++)
            {
                gridView1.SetRowCellValue(i, "Stt", i + 1);
            }

        }

        private void button1_Click(object sender, EventArgs e)
        {

            if (this.ddlWareHouseSale.SelectedValue == null || string.IsNullOrEmpty(this.ddlWareHouseSale.SelectedValue.ToString()))
            {
                MessageBox.Show("Chưa chọn kho");
                return;
            }

            if (dtpDateCreate.EditValue == null || string.IsNullOrEmpty(dtpDateCreate.EditValue.ToString()))
            {
                MessageBox.Show("Chưa chọn ngày");
                return;
            }
            wareHouseService=new WareHouseService();
            gridControl1.DataSource = wareHouseService.ReportExistByDay(int.Parse(ddlWareHouseSale.SelectedValue.ToString()),DateTime.Parse(dtpDateCreate.EditValue.ToString()));
            gridItems.DataSource = wareHouseService.ReportExistDetailByDay(int.Parse(ddlWareHouseSale.SelectedValue.ToString()), DateTime.Parse(dtpDateCreate.EditValue.ToString()));

            ReCanculateSTT();
        }
    }
}
